import { STask } from "../../../../Message/Game/STask";
import { ETaskType } from "../../../../Message/Game/ETaskType";
import { ETaskGroup } from "../../../../Message/Game/ETaskGroup";
import { Cache } from "../../cache/Cache";
import { TTaskConfig } from "../../../../Message/Db/Tables/TTaskConfig";
import { Reward } from "./Reward";
import { EReward } from "../../../../Message/Public/EReward";
import { ItemData } from "../../resource/info/ItemData";
import { TaskInfo } from "../../model/TaskInfo";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
import { SProcess } from "../../../../Message/Game/SProcess";
import { ETaskStatus } from "../../../../Message/Game/ETaskStatus";
import { GameMapUtil } from "../../scene/map/GameMapUtil";
import { MapFileUtil } from "../../scene/map/MapFileUtil";
import { TaskTargetType } from "./imgtxt/TaskTargetType";
import { SReward } from "../../../../Message/Public/SReward";
type int = number;
//class TaskUtil
    
    export  class TaskUtil
    {
        

        public static isPVPTask(arg1: STask): Boolean
        {
            if (arg1 == null) 
            {
                return false;
            }
            if (arg1.type == ETaskType._ETaskTypeCountryMoneyKnow) 
            {
                return true;
            }
            if (arg1.type == ETaskType._ETaskTypeCountryMoneyGive) 
            {
                return true;
            }
            if (arg1.group == ETaskGroup._ETaskGroupCrossSea) 
            {
                return true;
            }
            return false;
        }

        public static checkAndDelMyPVPTask(arg1: Array<any>): Array<any>
        {
            var loc1=null;
            var loc2=null;
            if (arg1 == null) 
            {
                return [];
            }
            if (Cache.instance.country.isOpenCountry) 
            {
                return arg1;
            }
            var loc3=[];
            var loc4=0;
            var loc5=arg1;
            for(loc1 of loc5) 
            {
                if (TaskUtil.isPVPTask(loc1.task)) 
                {
                    continue;
                }
                loc3.push(loc1);
            }
            return loc3;
        }

        public static checkAndDelCanGetPVPTask(arg1: Array<any>): Array<any>
        {
            var loc1=null;
            if (arg1 == null) 
            {
                return [];
            }
            if (Cache.instance.country.isOpenCountry) 
            {
                return arg1;
            }
            var loc2=[];
            var loc3=0;
            var loc4=arg1;
            for(loc1 of loc4) 
            {
                if (TaskUtil.isPVPTask(loc1)) 
                {
                    continue;
                }
                loc2.push(loc1);
            }
            return loc2;
        }

        public static checkAndDelNpcPVPTask(arg1: Array<any>): Array<any>
        {
            var loc1=null;
            if (arg1 == null) 
            {
                return [];
            }
            if (Cache.instance.country.isOpenCountry) 
            {
                return arg1;
            }
            var loc2=[];
            var loc3=0;
            var loc4=arg1;
            for(loc1 of loc4) 
            {
                if (TaskUtil.isPVPTask(loc1.task)) 
                {
                    continue;
                }
                loc2.push(loc1);
            }
            return loc2;
        }

        public static filterTaskGroup(arg1: Array<any>, arg2: int): Array<any>
        {
            var loc1=null;
            if (arg1 == null) 
            {
                return [];
            }
            var loc2=[];
            var loc3=0;
            var loc4=arg1;
            for(loc1 of loc4) 
            {
                if (loc1.group == arg2) 
                {
                    continue;
                }
                loc2.push(loc1);
            }
            return loc2;
        }

        public static parseTaskBonus(arg1: TTaskConfig): Reward
        {
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            var loc9=null;
            var loc1=new Reward();
            if (arg1 == null) 
            {
                return loc1;
            }
            var loc2=arg1.rewards.split("[");
            var loc3=0;
            while (loc3 < loc2.length) 
            {
                if (!((loc4 = loc2[loc3]) == null || loc4 == "")) 
                {
                    if (!((loc5 = (loc4 = loc4.split("]")[0]).split(",")).length < 3)) 
                    {
                        loc6 = loc5[0];
                        loc7 = int(loc5[1]);
                        loc8 = int(loc5[2]);
                        var loc10=loc6;
                        switch (loc10) 
                        {
                            case EReward._ERewardArena:
                            {
                                loc1.arena = loc8;
                                break;
                            }
                            case EReward._ERewardBloom:
                            {
                                loc1.bloom = loc8;
                                break;
                            }
                            case EReward._ERewardBufferGroup:
                            {
                                loc1.bufferGroup = loc8;
                                break;
                            }
                            case EReward._ERewardCoin:
                            {
                                loc1.coin = loc8;
                                break;
                            }
                            case EReward._ERewardCoinBind:
                            {
                                loc1.bindCoin = loc8;
                                break;
                            }
                            case EReward._ERewardContribution:
                            {
                                loc1.contribution = loc8;
                                break;
                            }
                            case EReward._ERewardCountryContribution:
                            {
                                loc1.countryContribution = loc8;
                                break;
                            }
                            case EReward._ERewardDiceCount:
                            {
                                loc1.diceCount = loc8;
                                break;
                            }
                            case EReward._ERewardExperience:
                            {
                                loc1.experience = loc8;
                                break;
                            }
                            case EReward._ERewardGoldBind:
                            {
                                loc1.bindGold = loc8;
                                break;
                            }
                            case EReward._ERewardGuildMoney:
                            {
                                loc1.guildMoney = loc8;
                                break;
                            }
                            case EReward._ERewardHonour:
                            {
                                loc1.honour = loc8;
                                break;
                            }
                            case EReward._ERewardItem:
                            {
                                (loc9 = new ItemData(loc7)).itemAmount = loc8;
                                loc1.items.push(loc9);
                            }
                            case EReward._ERewardNimbus:
                            {
                                loc1.lingQi = loc8;
                                break;
                            }
                            case EReward._ERewardPetCoin:
                            {
                                loc1.petCoin = loc8;
                                break;
                            }
                            case EReward._ERewardPoint:
                            {
                                loc1.point = loc8;
                                break;
                            }
                            case EReward._ERewardPrestige:
                            {
                                loc1.prestige = loc8;
                                break;
                            }
                            case EReward._ERewardTaskGroup:
                            {
                                loc1.taskGroup = loc8;
                                break;
                            }
                        }
                    }
                }
                ++loc3;
            }
            return loc1;
        }

        public static isCrossCountryTaskByProcesss(arg1: int, arg2: Array<any>): Boolean
        {
            var loc1=false;
            if (arg2 == null) 
            {
                return loc1;
            }
            var loc2=arg1;
            switch (loc2) 
            {
                case ETaskType._ETaskTypeTalk:
                {
                    loc1 = arg2[5] == 1;
                    break;
                }
                case ETaskType._ETaskTypeCollect: case ETaskType._ETaskTypeKillBossDrop:
                {
                    loc1 = arg2[8] == 1;
                    break;
                }
            }
            return loc1;
        }

        public static getTaskTargetInfo(arg1: TaskInfo, arg2: int, arg3: Boolean=false): TaskTargetInfo
        {
            var loc1=arg1.getTargetByIndex(arg2);
            if (arg3) 
            {
                loc1 = arg1.getDesTargetByIndex(arg2);
            }
            if (!(arg1.sTask.processes[arg2] == null) && TaskUtil.isCrossCountryTaskByProcesss(arg1.sTask.type, (arg1.sTask.processes[arg2] as SProcess).contents) && !(arg1.status == ETaskStatus._ETaskStatusWaitForCompleted) && !(arg1.status == ETaskStatus._ETaskStatusHadCompleted)) 
            {
                if (GameMapUtil.curMapState.isCrossCountry) 
                {
                    loc1.proxyId = MapFileUtil.proxyID;
                    loc1.serverId = MapFileUtil.serverID;
                    loc1.mapId = MapFileUtil.mapID;
                }
                else 
                {
                    return TaskTargetType.CrossTaskModule;
                }
            }
            return loc1;
        }

        public static getRewardsForCrossSpyTask(arg1: Array<any>): Array<any>
        {
            var loc3=null;
            if (arg1 == null) 
            {
                return arg1;
            }
            var loc1=arg1.concat();
            var loc2=0;
            while (loc2 < loc1.length) 
            {
                if ((loc3 = loc1[loc2] as SReward).type != EReward._ERewardExperience) 
                {
                    if (loc3.type == EReward._ERewardNimbus) 
                    {
                        loc3.num = (Cache.instance.role.roleInfo.level - 70) * 600 + loc3.num;
                    }
                }
                else 
                {
                    loc3.num = (Cache.instance.role.roleInfo.level - 70) * 12000 + loc3.num;
                }
                ++loc2;
            }
            return loc1;
        }

        public static isCanGetDoubleRewardTask(arg1: STask): Boolean
        {
            if (arg1 == null) 
            {
                return false;
            }
            return arg1.reserve1 > 0;
        }
    }
